{% macro markdown_link() %}
{% trans %}
<small>You can use <a target="_blank" href="http://en.wikipedia.org/wiki/Markdown">Markdown</a> syntax in your comments.</small>
{% endtrans %}
{% endmacro %}

{% macro render_post(post) %}
<h3>{% if post.permissions.vote %}
<span id="vote-{{ post.id }}">
    <a href="#" onclick="newsmeme.vote_post('{{ url_for('post.upvote', post_id=post.id) }}'); return false;"><img src="{{ theme_static("images/up-icon.png") }}"></a>
    <a href="#" onclick="newsmeme.vote_post('{{ url_for('post.downvote', post_id=post.id) }}'); return false;"><img src="{{ theme_static("images/down-icon.png") }}"></a>  
</span>
{% endif %}
<a href="{{ post.link if post.link else post.url }}" class="{{ post.access_name }}">{{ post.title }}</a>

{% if post.link %}
<span class="domain">&rarr; {{ post.domain }}</span>
{% endif %}

</h3>
<p class="post-info">
<a href="{{ post.url }}">Comments ({{ post.num_comments }})</a> | 
{{ _("Score") }} <span id="score-{{ post.id }}">{{ post.score }}</span> | 
{{ _("Posted") }} {{ _("%(date)s", date=post.date_created|timesince) }} 
<a href="{{ url_for('user.posts', username=post.author.username) }}">{{ post.author.username }}</a> 
    </p>    
    {% endmacro %}

{% macro render_comment(comment) %}

<li class="comment span-{{ 24 - comment.depth }} {% if comment.parent_id %}push-1{% endif %} last" id="comment-{{ comment.id }}">
<div class="comment-info">
<img src="{{ comment.author.gravatar_url(30) }}" alt="{{ comment.author.username }}">
<a href="{{ url_for('user.posts', username=comment.author.username) }}">{{ comment.author.username }}</a> 
{{ comment.date_created|timesince }}<br>
{% if comment.permissions.vote %}
   <span id="vote-comment-{{ comment.id }}">
       <a href="#" onclick="newsmeme.vote_comment('{{ url_for('comment.upvote', comment_id=comment.id) }}'); return false;"><img src="{{ theme_static("images/up-icon.png") }}"></a>
    <a href="#" onclick="newsmeme.vote_comment('{{ url_for('comment.downvote', comment_id=comment.id) }}'); return false;"><img src="{{ theme_static("images/down-icon.png") }}"></a>  
</span>
{% endif %}

{{ _("Score") }} <span id="score-comment-{{ comment.id }}">{{ comment.score }}</span> |
<a href="{{ comment.permalink }}">permalink</a> 
    {% if g.user %}

   | <a href="#" onclick="$('#comment-form-{{ comment.id }}').toggle();return false;">reply</a> | 

    {% if comment.permissions.edit %}
    <a href="#edit-comment-form-{{ comment.id }}" onclick="$('#edit-comment-form-{{ comment.id }}').toggle();">edit</a> |
    <a href="#" onclick="$('#delete-comment-{{ comment.id }}').toggle(); return false;">{{ _("delete") }}</a> 
    <div id="delete-comment-{{ comment.id }}" style="display:none;">
        <strong>{{ _("Are you sure you want to delete this comment ?") }} </strong>
        <a href="#" onclick="newsmeme.delete_comment('{{ url_for("comment.delete", comment_id=comment.id) }}'); return false;">{{ _("yes") }}</a> / 
        <a href="#" onclick="$('#delete-comment-{{ comment.id }}').toggle(); return false;">{{ _("no") }}</a>
    </div>
    {% else %}

    <a href="{{ url_for('comment.report_abuse', comment_id=comment.id) }}">{{ _("report abuse") }}</a> 

    {% endif %}

    {% endif %}
</div>

    <div {% if comment.score < 0 %}class="faded"{% endif %}>
    {% if comment.comment %}
    {{ comment.markdown }}
    {% endif %}
    </div>

    {% if g.user %}
    <form id="comment-form-{{ comment.id }}" 
          method="POST" 
          style="display:none;"
          action="{{ url_for('post.add_comment', post_id=post.id, parent_id=comment.id) }}">
        {{ comment_form.hidden_tag() }}
        <ul>
            <li>
            {{ comment_form.comment }}
            </li>
        <li>
        {{ comment_form.submit(value=_("Add comment")) }}
            </li>
            <li>
            </li>
        </ul>
    </form>
    
    {% if g.user.id == comment.author.id %}
    <form id="edit-comment-form-{{ comment.id }}"
        style="display:none;"
        method="POST"
        action="{{ url_for('comment.edit', comment_id=comment.id) }}">
        {% with form = edit_comment_form(comment) %}
        {{ form.hidden_tag() }}
        <ul>
            <li>
            {{ form.comment }} 
            </li>
            <li>
            {{ form.submit }}
            {{ form.cancel(onclick="$('#edit-comment-form-%d').toggle(); return false;" % comment.id) }}
            </li>
            {{ markdown_link() }}}
 
        </ul>
        {% endwith %}
    </form>
    {% endif %}

    {% endif %}

    {% if comment.comments %}
    <ul class="comments">
        {% for child_comment in comment.comments %}
        {{ render_comment(child_comment) }}
        {% endfor %}
    </ul>
    {% endif %}
</li>

{% endmacro %}


